package com.esms.esmsadmin.controller;

import com.esms.esmsadmin.entity.RespBean;
import com.esms.esmsadmin.entity.RespPageBean;
import com.esms.esmsadmin.entity.StudentEntity;
import com.esms.esmsadmin.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenhong
 * @version 1.0.0
 * @ClassName StudentController.java
 * @Description 学生类相关的controller
 * @createTime 2022年11月16日 10:18:00
 */

@RestController
@RequestMapping("/student/basic")
public class StudentController {
    @Autowired
    StudentService studentService;
    @GetMapping("/")
    public RespPageBean getStudentsByPage(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer size,
                                          String keywords) {
        return studentService.getStudentsByPage(page, size,keywords);
    }

    //添加学生
    @PostMapping("/")
    public RespBean addStudent(@RequestBody StudentEntity student){
        if(studentService.addStudent(student) == 1){
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    //更新学生信息
    @PutMapping("/")
    public RespBean updateStu(@RequestBody StudentEntity student) {
        if (studentService.updateStu(student) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    //删除学生
    @DeleteMapping("/{id}")
    public RespBean deleteStuByEid(@PathVariable Integer id) {
        if (studentService.deleteStuByEid(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

}
